package com.ang.regularExpression;

/**
 * @author ssang
 * @date 2022-01-27 15:54
 */
public class DateTimeRegTest {
    public static void main(String[] args) {
        DateTimeRegTest test = new DateTimeRegTest();
        test.test();
    }

    public void test(){
        String reg = "^([0-1]?[0-9]|2[0-3])(:[0-5][0-9]){2}$";//00:00:00-23:59:59
        System.out.println("00:00:00".matches(reg));//true
        System.out.println("8:00:00".matches(reg));//true
        System.out.println("08:00:00".matches(reg));//true
        System.out.println("11:00:00".matches(reg));//true
        System.out.println("23:59:59".matches(reg));//true
        System.out.println("11:00:60".matches(reg));//false
        System.out.println("24:00:00".matches(reg));//false
        System.out.println("===================================");

        String reg1 = "^(0?[0-9]|1[0-1])(:[0-5][0-9]){2}$";
        System.out.println("11:59:59".matches(reg1));//true
        System.out.println("12:59:59".matches(reg1));//false
        System.out.println("===================================");

        String reg2 = "^(1[2-9]|2[0-3])(:[0-5][0-9]){2}$";
        System.out.println("11:59:59".matches(reg2));//false
        System.out.println("12:59:59".matches(reg2));//true
        System.out.println("23:59:59".matches(reg2));//true
        System.out.println("===================================");

    }
}
